Programming Examples

Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.


Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.

Solution

m = int(input("Enter value of m: "))
n = int(input("Enter value of n: "))

total = 0

for i in range(m, n + 1):
    if i % 2 != 0:
        pass   # Skip odd numbers
    else:
        total += i

print("Sum of even numbers =", total)
Output

Enter value of m: 1

Enter value of n: 10

Sum of even numbers = 30


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad